Title Banner

Previous Book Contents Book Index Next

Inside Macintosh: QuickDraw GX Printing /
Chapter 3 - Page Formatting and Dialog Box Customization / Using Format Objects and Collection Items to Format Pages


Copying a Format Object for Use in Other Documents

When a user wants to disassociate a format from a particular document and associate it with another document, you use the GXNewFormat, GXCopyFormat, and GXDisposeFormat functions. For example, a user may have a three-page document that contains a format object for a single page in landscape orientation. This user may want to use the landscape page in another document and delete it from the original document.

Figure 3-17 shows two documents. Document A consists of two pages--one page uses the default format, the other uses a unique format object. Document B also consists of two pages--each page uses the default format. A user may decide to use the format of page 2 in Document A for page 1 of Document B.

Figure 3-17 Moving a format object from one document to another

Listing 3-14 shows how to move a format object from one document to another. The srcPage and srcDocument parameters to the MyMoveFormatToJob function in the listing represent the page's location in the original document. The destPage and destDocument parameters refer to the new location and document. Initially, a format object for the destination page does not exist.

Listing 3-14 Moving a format object from one document to another

OSErr MyMoveFormatToJob(long srcPage, MyDocumentPtr srcDocument, 
                        long destPage, MyDocumentPtr destDocument)
{
   OSErr       err;
   gxFormat    srcPgFormat, destPgFormat;

   /* 
      Get the source format object. If it is nil, create a
      destination format object from the source job object.
   */
   srcPgFormat = srcDocument->pageFormat[srcPage-1];
   if (srcPgFormat == nil)
      srcPgFormat = GXNewFormat(srcDocument->documentJob);

   /* 
      Create a new destination format object and copy the source 
      format object to it. Then dispose of the source format 
      object and clear out the source page's reference.
   */
   destPgFormat = GXNewFormat(destDocument->documentJob);
   GXCopyFormat(srcPgFormat, destPgFormat);
   GXDisposeFormat(srcPgFormat);
   srcDocument->pageFormat[srcPage-1] = nil;

   /* 
      If there were no errors, store the destination page's format 
      object reference.
   */
   err = GXGetJobError(srcDocument->documentJob);
   if (err == noErr)
      err = GXGetJobError(destDocument->documentJob);
   if (err == noErr)
      destDocument->pageFormat[destPage-1] = destPgFormat;
   return err;
}

Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996




Navigation graphic, see text links

Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help